def solve(weights: list[int], values: list[int], W: int) -> int:
    # 在此编写代码
    n = len(weights)
    dp = [0 for _ in range(W+1)]  # 空间为i的背包能装的最大价值
    for i in range(n):
        for j in range(W,weights[i] -1,-1):
            dp[j] = dp[j-weights[i]] + values[i] 
    return dp[W]

if __name__ == "__main__":
    n, W = map(int, input().split())
    weights = []
    values = []
    for _ in range(n):
        weight, value = map(int, input().split())
        weights.append(weight)
        values.append(value)

    print(solve(weights, values, W))
